home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
061-070
/
amok63
/
m2ced
/
txt.lha
/
M2CED.mod
< prev
next >
Wrap
Text File
|
1991-11-13
|
12KB
|
479 lines
(**********************************************************************
:Program. M2CED.mod
:Contents. Working with CED
:Author. Steffen Reith
:Address. Hessenstr. 64, D-8700 Wuerzburg
:Phone. None
:Copyright. Shareware
:Language. Modula-2
:Translator. M2Amiga A+L V3.2d
:Imports. ARP, CED, ErrorMsg, Errors, Keys, req, Msg, Config
:System. $$Date: 17-06-1991 13:14:59
:System. $$CompilerRuns #13#
:History. V1.0 9. June 1990
V1.1 12. June 1990 Some bugs fixed
V1.2 18. June 1990 Configuration added
V1.21 10. July 1990 little changes in Compile and Link
V1.3 7. August 1990 Key for M2O added
V1.31 23. Oct 1990 Fast load for "Fehler-Meldungen"
V1.32 6. Feb 1991 little Bug fixed
V1.4 13. Mrz 1991 New: UpdateVersion
V1.41 16. Jun 1991 New: Changed for M2Amiga V4.0
**********************************************************************)
(*$ StackParms:=FALSE Volatile:=FALSE CaseChk:=FALSE *)
(*$ StackChk:=FALSE RangeChk:=FALSE OverflowChk:=FALSE NilChk:=FALSE *)
MODULE M2CED;
FROM ARP IMPORT SyncRun,GADS,ToUpper;
FROM Arts IMPORT dosCmdBuf,dosCmdLen;
FROM CED IMPORT Fehler,FehlerType,Status,PutMsg2CED,TalkCED,KillString,
Ergeb;
FROM ErrorMsg IMPORT ReadList,KillList,FindMsg,String,NodePtr;
FROM Errors IMPORT ExistErrorFile,OpenErrorFile,NextError,CloseErrorFile,
ErrorFeld;
FROM Keys IMPORT KeyPressed,Action;
FROM req IMPORT DSize,FChars,PathTypePtr,PathType,GetString;
FROM IntuitionL IMPORT DisplayBeep,WBenchToFront;
FROM SYSTEM IMPORT ADDRESS,ADR;
FROM DosD IMPORT FileHandle,FileHandlePtr,newFile,readWrite,oldFile,
FileLockPtr,sharedLock;
FROM DosL IMPORT Open,Close,Delay,Write,Execute,CurrentDir,Lock,UnLock;
FROM String IMPORT Concat,Compare,Length;
FROM Conversions IMPORT ValToStr;
FROM Msg IMPORT TitleMsg,Request;
FROM Config IMPORT P,Para,WriteFile,ReadFile;
FROM Ver IMPORT UpdateVersion;
CONST ExtLen=4; (* Laenge der Namensextension *)
Template='N=NameOnly/s,A=Argument/s,R=NoRestart/s,V=NoVersion';
HelpMsg='Usage: M2CED [nur Filename] [Argument erfragen] [NoRestart] [NoVersion]';
CopyRightMsgC=' M2CED Version1.4(alpha) © by Steffen Reith is active';
TYPE ExtType=ARRAY[0..ExtLen] OF CHAR; (* Laenge nur fuer M2-Amiga geeignet *)
Sort=(FullPath,NameOnly);
BOOLEANPtr=POINTER TO BOOLEAN;
ArgType=RECORD
NameO,Argument,NoRestart,NoVersion:BOOLEANPtr
END;
DosWin=ARRAY[0..63] OF CHAR;
VAR Root:NodePtr;
Key:CARDINAL;
StartArgument:ARRAY[0..255] OF CHAR;
CopyRightMsg:ARRAY[0..63] OF CHAR;
Flag,ErrorsOn:BOOLEAN;
Argc:INTEGER;
Arg:ArgType;
Old:FileLockPtr;
OldFile,OpenName:PathType;
Compiled:BOOLEAN;
OffSet:LONGINT;
Jump,JumpNo:ARRAY[0..16] OF CHAR;
PROCEDURE ReportCEDError();
VAR Text:ARRAY[0..31] OF CHAR;
BEGIN
CASE Fehler OF
|ok:Text:='Internal FATAL Error';
|noReply:Text:='Keine Replyport';
|noCED:Text:='Kein CED da !!!!';
END;
Request(Text)
END ReportCEDError;
PROCEDURE Cont();
VAR Erg:Action;
BEGIN
REPEAT
Erg:=KeyPressed()
UNTIL Erg=continue
END Cont;
PROCEDURE ChangeDir(VAR Dir:ARRAY OF CHAR);
VAR MyLock:FileLockPtr;
Msg:ARRAY[0..31] OF CHAR;
BEGIN
MyLock:=Lock(ADR(Dir),sharedLock);
IF MyLock=NIL THEN
Msg:='Kann Directory nicht wechseln!';
TitleMsg(Msg);
RETURN
END;
MyLock:=CurrentDir(MyLock);
UnLock(MyLock)
END ChangeDir;
PROCEDURE GetCEDFileExtension(VAR Ext:ExtType);
VAR Flag:BOOLEAN;
Help:PathType;
i:INTEGER;
BEGIN
Flag:=TalkCED('Status 21'); (* Filenamen ohne Pfad *)
IF NOT(Flag) THEN
ReportCEDError();
RETURN
END;
Help:=Status^;
i:=0;
WHILE (Help[i]#'.') AND (i<FChars+DSize) DO INC(i) END; (* Nach . suchen *)
IF i=FChars+DSize THEN Ext:=''; RETURN END;
Ext[0]:=Help[i]; Ext[1]:=Help[i+1];
Ext[2]:=Help[i+2]; Ext[3]:=Help[i+3]; Ext[4]:=CHAR(0);
KillString(Status)
END GetCEDFileExtension;
PROCEDURE GetCEDFileName(VAR Name:PathType;PathSort:Sort);
VAR Flag:BOOLEAN;
i:INTEGER;
Help:PathType;
BEGIN
Name:='';
Help:='Status ';
IF PathSort=FullPath THEN
Concat(Help,'19')
ELSE
Concat(Help,'21')
END;
Flag:=TalkCED(Help);
IF NOT (Flag) THEN
ReportCEDError();
RETURN
END;
Help:=Status^;
i:=0;
WHILE (i<(1+FChars+DSize)) AND (Help[i]#'.') DO INC(i) END;
Help[i]:=CHAR(0);
Name:=Help;
KillString(Status)
END GetCEDFileName;
PROCEDURE NameLen(Ptr:ADDRESS):INTEGER; (* Wird benoetigt weil CED oft *)
(* keine nullterminierte Strings *)
TYPE IntPtr=POINTER TO LONGINT; (* zurueckliefert *)
VAR IPtr:IntPtr;
BEGIN
IPtr:=Ptr;
DEC(IPtr,4);
RETURN IPtr^
END NameLen;
PROCEDURE GetCEDPath(VAR Path:PathType);
VAR i:INTEGER;
Help:PathType;
BEGIN
Path:='';
Help:='Status 19';
Flag:=TalkCED(Help);
IF NOT (Flag) THEN
ReportCEDError();
RETURN
END;
Help:=Status^;
i:=NameLen(Status);
WHILE (Help[i]#'/') AND (Help[i]#':') AND (i>0) DO DEC(i) END;
IF Help[i]=':' THEN
Help[i+1]:=CHAR(0)
ELSE
Help[i]:=CHAR(0)
END;
Path:=Help;
KillString(Status)
END GetCEDPath;
PROCEDURE ExistFile(FileName:ARRAY OF CHAR):BOOLEAN;
VAR File:FileHandlePtr;
BEGIN
File:=Open(ADR(FileName),oldFile);
IF File=NIL THEN
RETURN FALSE
ELSE
Close(File);
RETURN TRUE
END
END ExistFile;
PROCEDURE LoadErrors();
VAR Name,Name2:PathType;
Ext:ExtType;
i:CARDINAL;
BEGIN
CloseErrorFile();
ErrorsOn:=TRUE;
GetCEDFileName(Name,FullPath);
GetCEDFileExtension(Ext);Concat(Name,Ext);
Concat(Name,'e');
IF NOT(ExistErrorFile(Name)) THEN
Name:='txt/'; (* Arbeitet jemand mit txt-Dirs ??? *)
GetCEDFileName(Name2,NameOnly);
Concat(Name,Name2);Concat(Name,Ext);Concat(Name,'e');
IF NOT(ExistErrorFile(Name)) THEN
TitleMsg('Kann kein Errorfile finden ');
ErrorsOn:=FALSE;
RETURN
END
END;
OpenErrorFile(Name)
END LoadErrors;
PROCEDURE FindErrors();
CONST IntLen=10;
KommandLen=20;
VAR SourcePos:LONGCARD;
i:INTEGER;
ErrorNums:ErrorFeld;
PosStr:ARRAY[0..IntLen] OF CHAR;
Msg:ARRAY[0..KommandLen] OF CHAR;
ErrMsg,OutTxt:String;
err,Flag:BOOLEAN;
BEGIN
IF ErrorsOn THEN
NextError(SourcePos,ErrorNums);
IF (SourcePos=0) AND (ErrorNums[1]=0) THEN
CloseErrorFile();
ErrorsOn:=FALSE;
TitleMsg('Kein (weiterer) Fehler gefunden');
Flag:=PutMsg2CED('Jump To Byte 0');
RETURN
END;
ValToStr(SourcePos,FALSE,PosStr,10,-1*SIZE(PosStr),CHAR(0),err);
IF err THEN
TitleMsg('Interner Fataler Fehler I');DisplayBeep(NIL);Delay(50);RETURN;
END;
Msg:='Jump To Byte ';Concat(Msg,PosStr);
Flag:=PutMsg2CED(Msg);
IF NOT(Flag) THEN
PosStr:='0';
ReportCEDError()
END;
i:=1;
OutTxt:='';
WHILE ErrorNums[i]#0 DO
FindMsg(Root,ErrorNums[i],ErrMsg);
Concat(OutTxt,ErrMsg);
Concat(OutTxt,' ');
INC(i)
END;
TitleMsg(OutTxt);
END
END FindErrors;
PROCEDURE Compile(VAR Compiled:BOOLEAN);
VAR Name,Name2,Name3:PathType;
Dummy,Offset:LONGINT;
out,help:FileHandlePtr;
Kommando:ARRAY [0..DSize+FChars+5] OF CHAR;
Flag,ChgDir:BOOLEAN;
Ext:ExtType;
Title:DosWin;
BEGIN
ErrorsOn:=FALSE;
CloseErrorFile();
Title:='';Concat(Title,Para.Window);Concat(Title,'M2C Compiling ...');
out:=Open(ADR(Title),newFile);
Kommando:='';Concat(Kommando,Para.CompilerName);
IF (Argc>0) AND (Arg.NameO^) THEN
GetCEDPath(Name);
ChangeDir(Name); (* Compile im aktuellen Dir laufen lassen ! *)
GetCEDFileName(Name,NameOnly);
ELSE
GetCEDFileName(Name,FullPath)
END;
Concat(Kommando,Name);
GetCEDFileExtension(Ext);
IF NOT(Arg.NoRestart^) THEN (* Restartfile schreiben ?? *)
GetCEDFileName(Name3,FullPath);Concat(Name3,Ext);
Flag:=TalkCED('Status 56');
OffSet:=Ergeb;
Flag:=TalkCED('Status 46');
OffSet:=OffSet+Ergeb; (* Bestimme Byteoffset im File *)
WriteFile(Name3,OffSet) (* Fuer Neustart *)
END;
IF (Compare(Ext,'.def')=0) THEN Concat(Kommando,Ext) END;
Flag:=WBenchToFront();
IF NOT(Arg.NoVersion^) THEN UpdateVersion() END;
Flag:=PutMsg2CED("Save all Changes");
Dummy:=Execute(ADR(Kommando),NIL,out);
(* Name normale Fehlerdatei Name2 Fehlerdatei in TXT Dir *)
Concat(Name,Ext);Concat(Name,'e');
GetCEDFileName(Name3,NameOnly);
Name2:='txt/';
Concat(Name2,Name3);Concat(Name2,Ext);Concat(Name2,'e');
IF ExistErrorFile(Name) OR ExistErrorFile(Name2) THEN (* Festellen ob Fehler*)
Dummy:=Write(out,ADR(Para.ContMsg),SIZE(Para.ContMsg));
Cont();
Flag:=PutMsg2CED('CEDToFront');
LoadErrors();
FindErrors()
ELSE
Flag:=PutMsg2CED('CEDToFront');
Compiled:=TRUE (* Compiler ist ohne Fehler durchgelaufen *)
END;
Close(out)
END Compile;
PROCEDURE Link(VAR Compiled:BOOLEAN; Opti:BOOLEAN);
VAR Name:PathType;
Dummy:LONGINT;
out:FileHandlePtr;
Kommando:ARRAY [0..DSize+FChars+5] OF CHAR;
Flag:BOOLEAN;
Ext:ExtType;
Title:DosWin;
BEGIN
ErrorsOn:=FALSE;
CloseErrorFile();
GetCEDFileName(Name,NameOnly);
GetCEDFileExtension(Ext);
IF (Compare(Ext,'.def')=0) THEN
TitleMsg('.DEF Files koennen nicht gelinkt werden !!!');
RETURN
END;
Title:='';Concat(Title,Para.Window);Concat(Title,'M2L Linking ...');
out:=Open(ADR(Title),newFile);
IF Opti THEN
Kommando:='';Concat(Kommando,Para.OptimizerName);
ELSE
Kommando:='';Concat(Kommando,Para.LinkerName);
END;
Concat(Kommando,Name);
Flag:=WBenchToFront();
Dummy:=Execute(ADR(Kommando),NIL,out);
Delay(25); (* Noch warten *)
Flag:=PutMsg2CED('CEDToFront');
Close(out);
Delay(25); (* Noch warten *)
IF NOT(Compiled) THEN
TitleMsg('Warning: Compiler war vor dem Linker nicht aktiv !!')
END;
Compiled:=FALSE
END Link;
PROCEDURE Start();
VAR Name:PathType;
Dummy:LONGINT;
Flag,Enter:BOOLEAN;
inout:FileHandlePtr;
Title:DosWin;
BEGIN
ErrorsOn:=FALSE;
CloseErrorFile();
GetCEDFileName(Name,NameOnly);
Flag:=WBenchToFront();
Title:='';Concat(Title,Para.Window);Concat(Title,'M2 Executing ...');
inout:=Open(ADR(Title),readWrite);
IF Arg.Argument^ THEN
Enter:=GetString(ADR(StartArgument),ADR('Argument ?'),NIL,20,
SIZE(StartArgument)-1);
IF NOT(Enter) THEN StartArgument:='' END;
Dummy:=SyncRun(ADR(Name),ADR(StartArgument),inout,inout);
ELSE
Dummy:=SyncRun(ADR(Name),NIL,inout,inout);
END;
Dummy:=Write(inout,ADR(Para.ContMsg),SIZE(Para.ContMsg));
Cont();
Close(inout);
Flag:=PutMsg2CED('CEDToFront');
END Start;
BEGIN
Arg.NameO^:=FALSE;
Arg.Argument^:=FALSE;
Arg.NoRestart^:=FALSE;
Arg.NoVersion^:=FALSE;
Argc:=GADS(dosCmdBuf,dosCmdLen,ADR(HelpMsg),ADR(Arg),ADR(Template));
StartArgument:='';
ReadList(Root);
ErrorsOn:=FALSE;
Flag:=PutMsg2CED('CEDToFront');
IF NOT Flag THEN ReportCEDError() END;
IF NOT(Arg.NoRestart^) THEN
ReadFile(OldFile,OffSet); (* evtl. altes File und Offset laden *)
ValToStr(OffSet,FALSE,JumpNo,10,-SIZE(JumpNo),CHAR(0),Flag);
(* Byteoffset ausrechnen *)
IF Flag THEN
Request('Kann Cursor nicht positionieren');
JumpNo:='0'
END;
Jump:='Jump To Byte ';Concat(Jump,JumpNo);
Flag:=PutMsg2CED(Jump);
OpenName:='Open ';
Concat(OpenName,OldFile)
ELSE
OpenName:='Open';
JumpNo:='0';
END;
Flag:=PutMsg2CED(OpenName);
Jump:='Jump To Byte ';Concat(Jump,JumpNo);
Flag:=PutMsg2CED(Jump);
Delay(25);
CopyRightMsg:=CopyRightMsgC;
TitleMsg(CopyRightMsg);
Compiled:=FALSE; (* Flag ob Compiler vor Linker gelaufen ist *)
LOOP
CASE KeyPressed() OF
|compile:Compile(Compiled);
|link:Link(Compiled,FALSE);
|opt:Link(Compiled,TRUE);
|start:Start();
|findError:FindErrors();
|load:LoadErrors();
|cancel:DisplayBeep(NIL);EXIT;
ELSE
END
END;
KillList(Root);
END M2CED.